<div class="main-content">
    <div class="section__content section__content--p20">
        <div class="container-fluid">
            <div class="row m-b-30">
                <div class="col-lg-12">
                    <div class="overview-wrap">
                        <h2 class="title-1">片段管理</h2>
                        <button class="au-btn au-btn-icon au-btn--blue"  onclick="showedit(0)">
                            <i class="zmdi zmdi-plus"></i>添加片段</button>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-lg-12">
                    <div class="table-responsive table--no-card m-b-30">
                    <table class="table table-borderless table-striped table-earning ">
                        <thead>
                        <tr>
                            <th>标题</th>
                            <th>键值</th>
                            <th>工具</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php
                        if (sizeof($fragments) > 0) {
                            foreach ($fragments as $i) {
                                ?>
                                <tr>
                                    <td><?php echo $i['title']; ?></td>
                                    <td><?php echo $i['key']; ?></td>
                                    <td>
                                        <button type="button" class="btn btn-primary btn-sm" onclick="showedit(<?php echo $i['id']; ?>)">编辑</button>
                                        <button type="button" class="btn btn-danger btn-sm" onclick="del(<?php echo $i['id']; ?>)">删除</button>
                                    </td>
                                </tr>
                                <?php
                            }
                        }
                        ?>
                        </tbody>
                    </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    function showedit(id) {
        if (id == 0) {
            window.location.href = "index.php?r=admin/fragment/add&id=" + id;
            return;
        }
        window.location.href = "index.php?r=admin/fragment/showedit&id=" + id;
    }
    function del(id) {
        $("#confirmModal_text").text('是否删除片段？');
        $("#confirmModalButton").bind("click",function () {
            $.get('index.php?r=admin/fragment/del', {id: id}, function (result) {
                if (message(result)) {
                    window.location.href = "index.php?r=admin/fragment/index";
                }
            }, 'json');
        });
    }
</script>